package com.randi.system.domain.entity.sysNotice;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.randi.common.core.domain.BaseEntity;
import com.randi.common.xss.Xss;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Transient;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

/**
 * @author ziye
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("sys_notice")
@ApiModel(value = "SysNotice", description = "公告信息")
public class SysNotice extends BaseEntity {

    @TableId(value = "notice_id", type = IdType.AUTO)
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "公告ID")
    private Long noticeId;

    @NotBlank(message = "公告类型不能为空")
    @TableField(value = "`notice_type`")
    @ApiModelProperty(value = "公告类型")
    private Integer noticeType;

    @Xss(message = "公告标题不能包含脚本字符")
    @NotBlank(message = "公告标题不能为空")
    @Size(max = 50, message = "公告标题不能超过50个字符")
    @TableField(value = "`notice_title`")
    @ApiModelProperty(value = "公告标题")
    private String noticeTitle;

    @TableField(value = "`notice_content`")
    @ApiModelProperty(value = "公告内容")
    private String noticeContent;

    @TableField(value = "`push_range`")
    @ApiModelProperty(value = "推送范围")
    private Integer pushRange;

    @TableField(value = "`notice_type_name`", exist = false)
    @ApiModelProperty(value = "公告类型名称")
    private String noticeTypeName;

    @TableField(value = "`push_range_name`", exist = false)
    @ApiModelProperty(value = "推送范围名称")
    private String pushRangeName;

    @Transient
    public String getKey() {
        return this.noticeId == null ? "" : this.noticeId.toString();
    }

}
